﻿using Admin.ApplicationLib.Services;
using Admin.CommonLib.Constants;
using Admin.CommonLib.Models.Organization;
using Microsoft.AspNetCore.Mvc;

namespace Admin.WebApi.Controllers
{
    [ApiController]
    public class OrganizationController : ControllerBase
    {
        private readonly IOrganizationService _organizationService;

        public OrganizationController(IOrganizationService organizationService)
        {
            this._organizationService = organizationService;
        }


        [HttpGet(ApiRoutes.Organization.QueryOrganizations)]
        public async Task<IActionResult> Get([FromQuery] OrganizationSearchRequestDto model)
        {
            if (model.Page > 0 || model.Limit > 0)
            {
                var data = await _organizationService.QueryOrganizationsByPageAsync(model);
                return Ok(data);
            }
            else
            {
                var data = await _organizationService.QueryOrganizationsAsync(model);
                return Ok(data);
            }
        }

        [HttpPost(ApiRoutes.Organization.CreateOrganization)]
        public async Task<IActionResult> Post(OrganizationEditRequestDto model)
        {
            var result = await _organizationService.CreateOrganization(model);
            return Ok(result);
        }
    }
}